﻿function view() {

    cppei.install();

    var app = angular.module('upLoadApp', []);

    app.controller("upLoadCtr", function ($scope, $http) {
        $scope.uploadMediaInfo = {};

        $scope.getClientList = function () {
            $http({
                method: 'get',
                url: cppei.api.getUrl('Client', 'GetList'),
                cache: false,
                params: { t: new Date().getTime() }
            }).success(function (result, status) {
                if (result.isSuccess) {
                    $scope.clientItem = result.data.items;
                } else {
                    cppei.growlError(result.message);
                }
            }).error(function (result, status) {
                cppei.growlError(result.message);
            });
        };

        $scope.ajaxFileUpload = function () {
            $.ajaxFileUpload({
                url: cppei.api.getUrl('cms','media', 'upload'),
                secureuri: false,
                fileElementId: 'fileToUpload',
                dataType: 'json', //or json xml whatever you like~ 
                //type:"post",
                // data: { 'sys:sno': 'Channel', 'sys:act': 'Upload' },
                success: function (result, status) {
                    // debugger;
                    if (result.isSuccess) {
                        $scope.$apply(function () {
                            $scope.uploadMediaInfo.id = result.data.id;
                            $scope.uploadMediaInfo.relativeFilePath = result.data.relativeFilePath;

                            $scope.currentStepIndex = 1;
                        });
                    } else {
                        cppei.growlError(result.message);
                    }

                },
                error: function (result, status, e) {
                    cppei.growlError(result.message);
                }
            });
        };

        $scope.onCheck = function (assembly, selectedClientId) {
            // debugger;
            // $scope.$apply(function () {
         //   console.log("ClientIdselected clientid :" + selectedClientId);
          //  console.log("selectedClientId clientid :" + $scope.selectedClientId);
            assembly.clientId = selectedClientId;
            console.log("onCheck clientid :" + assembly.clientId);
            // });

        };

        $scope.onCreate = function (isValid) {
          // debugger;
            if (!isValid) {
                $http({
                    method: 'post',
                    url: cppei.api.getUrl('cms', 'media', 'create'),
                    cache: false,
                    data: {
                        id: $scope.uploadMediaInfo.id,
                        relativeFilePath: $scope.uploadMediaInfo.relativeFilePath,
                        description: $scope.uploadMediaInfo.description
                    }
                }).success(function (result, status) {
                    if (result.isSuccess) {
                        cppei.growl('创建成功！');
                    } else {
                        cppei.growlError(result.Message);
                    }
                }).error(function (result, status) {
                    cppei.growlError(result.Message);
                });
            } else {
                cppei.growl('name和程序集类型均不能为空！');
            }

        }

        //$scope.getClientList();

        //当前操作步骤
        $scope.currentStepIndex = 0;

        //判断当前活动div
        $scope.isActiveStep = function (stepIndex) {
            if (stepIndex == $scope.currentStepIndex) {
                return true;
            } else {
                return false;
            }
        }

        //当前经过的步骤
        $scope.isPassedStep = function (stepIndex) {
            if (stepIndex <= $scope.currentStepIndex) {
                return true;
            } else {
                return false;
            }
        }

        //当前步骤下活动的按钮
        $scope.isVisible = function (stepindex) {
            //debugger;
            if (stepindex == $scope.currentStepIndex) {
                return 'block';
            } else {
                return 'none';
            }
        }

        //上一步
        $scope.prev = function () {
            $scope.currentStepIndex = 0;
        };

        //完成
        $scope.onFinish = function () {
            if ($scope.assemblyList.length > 0) {
                console.log("onFinish is begin");
                cppei.confirm('提示', '您还有通道未创建，是否继续关闭此窗口？', function (result) {
                    if (result) {
                        cppei.closeDialog(true, { value: 1 });
                    }
                });
                console.log("onFinish is end");
            } else {
                cppei.closeDialog(true, { value: 1 });
            }
        }
    });

    jQuery(function ($) {
        $(' #fileToUpload').ace_file_input({
            no_file: 'No File ...',
            btn_choose: 'Choose',
            btn_change: 'Change',
            // droppable: false,
            onchange: null,
            thumbnail: false //| true | large
            //whitelist:'dll',
            // blacklist:'exe'
            //onchange:''
            //
        });

    })
}